package com.dhl.fin.api.enums;

import com.dhl.fin.api.common.util.ObjectUtil;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author CuiJianbo
 * @since 2025/3/19
 */
@Getter
public enum BusinessTypeEnum {

    TIME_INCOME(1, "存钱", true),

    TIME_OUT(2, "取钱", false),

    FIX_INCOME(3, "存定期", false),

    FIX_OUT(4, "取定期", true),

    FAIR_INVOICE(5, "平账", false),

    TIME_TO_FIX(6, "活期转定期", false),

    TIME_INTEREST(7, "活期利息", true),

    FIX_MONEY(8, "定期存款", true),

    FIX_MONEY_INTEREST(9, "定期存款利息", true),

    LEND_OUT_MONEY(10, "借出", false),

    LEND_RETURN_BACK_MONEY(11, "收回", true),

    LEND_INTEREST_MONEY(12, "借出利息收入", true);

    private Integer code;

    private String name;

    /**
     * 对于活期余额来说，流出表示负数，流进表示正数
     * 对余额没有影响的就随便写
     */
    private Boolean positive;

    BusinessTypeEnum(Integer code, String name, Boolean positive) {
        this.code = code;
        this.name = name;
        this.positive = positive;
    }

    public static String getNameByCode(Integer code) {
        BusinessTypeEnum type = Arrays.stream(BusinessTypeEnum.values())
                .filter(item -> item.code.equals(code))
                .findFirst().orElse(null);
        if (ObjectUtil.notNull(type)) {
            return type.getName();
        }
        return null;
    }

    public static BusinessTypeEnum getByName(String name) {
        BusinessTypeEnum type = Arrays.stream(BusinessTypeEnum.values())
                .filter(item -> item.name.equals(name))
                .findFirst().orElse(null);
        if (ObjectUtil.notNull(type)) {
            return type;
        }
        return null;
    }


}
